#include <iostream>
#include <algorithm>

using namespace std;

const int N = 1010;

struct node
{
    int index;
    int cnt;
}row[N],col[N];

int m,n,k,l,d;

bool cmp1(node& x,node& y)
{
    return x.cnt > y.cnt;
}
bool cmp2(node& x,node& y)
{
    return x.index < y.index;
}
int main()
{
    cin >> m >> n >> k >> l >> d;
    //初始化结构体数组   
    for(int i = 1;i <= m;i++)
    {
        row[i].index = i;
    }
    for(int i = 1;i <= n;i++)
    {
        col[i].index = i;
    }
    while(d--)
    {
        int x,y,p,q;
        cin >> x >> y >> p >> q;
        if(x == p)
        {
            col[min(y,q)].cnt++;
        }
        else
        {
            row[min(x,p)].cnt++;
        }
    }
    //对两个数组按照cnt排序
    sort(row + 1,row + 1 + m,cmp1);
    sort(col + 1,col + 1 + n,cmp1);
    //对row数组,前k个元素,按照下标从小到大排序
    sort(row + 1,row + 1 + k,cmp2);
    sort(col + 1,col + 1 + l,cmp2);
    for(int i = 1;i <= k;i++)
    {
        cout << row[i].index << " ";
    }
    cout << endl;
    for(int i = 1;i <= l;i++)
    {
        cout << col[i].index << " ";
    }
    cout << endl;
    return 0;
}
